/**
 * 快捷加入购物车 ---- 商品推荐右下角快捷加入购物车
 */
define(function(require,exports,module) {
	// require('./plug/hammer.min');
	var myPub = require('./public');


	//添加购物车动画
	var oMoveIcon = $('.js_moveIcon');          //加入购物车动态标记
	var oFooter = $('.js_footer');      		//底部
	var oShopCarTip = $('.js_userNum');
    var clearTime;
    var oGoodsList = $('.js_goodsList');
    var oGoodsAddQuick = $('.js_goodsAddQuick');

    var AddBtn, time1, time2;
    var dbTapOff = true;



	oGoodsAddQuick.hammer().on('tap',function(e) {
		if(dbTapOff) { //阻止多次点击 true 可点击
		    var _tag = e.gesture.target;
            var $target;
            _tag.nodeName.toLowerCase() == 'p' ? $target = $(_tag) : $target = $(_tag).parents('p')
		    var _X = e.gesture.center.x;
		    var _Y = e.gesture.center.y;
		    var win_Width = $(window).width();
           	var win_Height = $(window).height();
		    var oFooterH = oFooter.height();

		    var pid = $target.parents('li').find('.js_addCar').attr('pId');
		    var quantity = 1;
		    if($target.parents('li').find('.js_sumNum').length != 0){
		    	quantity = $target.parents('li').find('.js_sumNum').val();
		    }
		    if($target.length > 0 && $target[0].className == 'addCar js_addCar') {
		    	dbTapOff = false;
		    	//var aLi = $(this).find('.js_addCar');
		    	//判断是商家页面 改变动画 left和top
                if(window.location.pathname.search('supplier/toSupplier') > 0) {
                	var oSideBox = $('.js_sideBox')
	    			var sLeft = oSideBox.position().left + oMoveIcon.width()/2;
                	var sTop = oSideBox.position().top + oMoveIcon.width()*1.5;
	    		}
	    		else {
	    			var sLeft = win_Width * 0.63 - oMoveIcon.width()/2;
                	var sTop = win_Height - oFooterH - oMoveIcon.height() - oMoveIcon.height()/10;
	    		}

		    	G_JSON_POST('/shop/cartItem/addCart',{"pId": pid, "quantity": quantity},function(data){
		    		if (data.status == "success") {

		    			var totalQuantity = data.totalQuantity;
		                 myPub.AddCarAnimate(_X,_Y,oMoveIcon,sLeft,sTop,oFooterH,function() {
		                	 oShopCarTip.show().html(totalQuantity).addClass('mybounceIn')
			                    clearTimeout(clearTime);
			                    clearTime = setTimeout(function() {

			                        oShopCarTip.removeClass('mybounceIn');

			                        dbTapOff = true;
			                    },1200);
			                });
		    		} else {
		    			myPub.TipLayer(data.message);
		    			clearTimeout(time1);
		    			time1 = setTimeout(function(){dbTapOff = true;},1200)

		        	}
		    		myPub.HamstopPropaga();
		        },function() {},function() {
		        	//完成
		        	clearTimeout(time2);
	    			time2 = setTimeout(function(){dbTapOff = true;},1200)
		        });

		       	myPub.HamstopPropaga();
		    	e.stopPropagation();
		    }


	    }
	});
});

